import Vue from 'vue'

Vue.directive('debounce', {
    inserted(el, binding) {
        let timerId; // 计时器ID
        el.addEventListener('click', () => {
            if (timerId) {
                clearTimeout(timerId); // 清除之前的计时器
                timerId = null
            }
            timerId = setTimeout(() => {
                if (typeof binding.value === 'function') {
                    binding.value();
                } else {
                    console.error("未提供有效的回调函数");
                }
            }, parseInt(binding.arg || 300));
        });
    }
})